<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>函数封装小练习</title>
</head>

<body>
  <script>
    // 函数封装小练习
    // 1. 求2个数的和，封装到函数里面
    // function sum() {
    //   let x = 10
    //   let y = 20
    //   console.log(x + y)
    // }
    // sum()

    // 2. 求1~100之间的累加和，封装到函数里面
    function sum() {
      let sum = 0
      for (let i = 1; i <= 100; i++) {
        sum += i
      }
      console.log(sum)
    }
    sum()
    sum()
  </script>
</body>

</html>